﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

using RexToy.UI.WinForm.Pmlx;

namespace RexToy.UI.WinForm.Controls
{
    public static class DefaultTemplateParser
    {
        private const string Context_Menu = "ContextMenu";
        private const string STATUS_BAR = "StatusBar";
        public static void ParseContextMenu(this ITemplateItem ctrl, PmlxNode px)
        {
            PmlxNode x = px.NavigateToSingleOrNull(Context_Menu);
            if (x == null)
                return;

            ToolStrip ts = ToolStripBuilder.BuildMenu(x);
            ContextMenuStrip ctxMenu = ts as ContextMenuStrip;
            if (ctxMenu == null)
                ThrowHelper.ThrowUnexpectedType(typeof(ContextMenuStrip), ts.GetType());
            Control c = ctrl as Control;
            c.ContextMenuStrip = ctxMenu;
        }

        public static void ParseStatusBar(this ITemplateItem ctrl, PmlxNode px)
        {
            var xStatus = px.NavigateToSingleOrNull(STATUS_BAR);
            if (xStatus != null)
            {
                System.Windows.Forms.ToolStrip ts = ToolStripBuilder.BuildStatus(xStatus);
                Control c = ctrl as Control;
                c.Controls.Add(ts);
            }
        }
    }
}
